<?php
/**
 * @ Fmash Top System
 * @ version: 3.0
 * @ author: i.coffee.smile@mail.com
 * @ date:2011-1-28
 * @ file:upload_tmp.php $22
 */
 
header("Content-type: text/html; charset=utf-8"); 
include_once 'class_mysql.php';
include_once 'wordstream.php';
include_once 'upload_check.php';

if(empty($_POST['name']))
{
	$message = '您必须填写姓名';
	$message = rawurlencode($message);
	header("location:upload_error.php?error=$message");
	exit();
}elseif(empty($_POST['grade']))
{
	$message = '您必须填写年级';
	$message = rawurlencode($message);
	header("location:upload_error.php?error=$message");
	exit();
}elseif(empty($_POST['branch']))
{
	$message = '您必须填写院系';
	$message = rawurlencode($message);
	header("location:upload_error.php?error=$message");
	exit();
}elseif(!is_uploaded_file($_FILES['upfile']['tmp_name'])){
	$message = '您必须上传照片';
	$message = rawurlencode($message);
	header("location:upload_error.php?error=$message");
	exit();
}
$tmp_name = $_FILES["upfile"]["tmp_name"];
$type = checkTitle($tmp_name);
if($type == 'jpg' || $type == 'bmp' || $type == 'png' || $type =='gif')
{
}else{
	$message = '您上传的文件属于非法文件！';
	$message = rawurlencode($message);
	header("location:upload_error.php?error=$message");
	exit();
}
if($_FILES["upfile"]["size"] >'102400')
{
	$message = '照片大于100KB!';
	$message = rawurlencode($message);
	header("location:upload_error.php?error=$message");
	exit();
}
list($width,$high)=getimagesize($_FILES['upfile']['tmp_name']);
if($width != 200 && $high != 200)
{
	$message = '为了整体美观，请保持图片<br>宽度200px，高度200px！';
	$message = rawurlencode($message);
	header("location:upload_error.php?error=$message");
	exit();
}

$upfile = $_FILES['upfile'];
$exp_file = explode('.',$upfile['name']);
$d = count($exp_file)-1;


if($exp_file[$d] == 'jpg' || $exp_file[$d] == 'bmp' || $exp_file[$d] == 'png' || $exp_file[$d] =='gif')
{
	$file_name = time().rand(1,100).'.'."$exp_file[$d]";
}else{
	$message = '您上传的文件不是图片格式！';
	$message = rawurlencode($message);
	header("location:upload_error.php?error=$message");
	exit();
}

$girl_name = incheck($_POST['name']);
$girl_grade = incheck($_POST['grade']);
$girl_branch = incheck($_POST['branch']);
if(empty($_POST['mobile']) || $_POST['mobile'] == '')
{
	$girl_mobile = 'NULL';
}else{
	$girl_mobile = checktel($_POST['mobile']);
}
if(empty($_POST['qq']) || $_POST['qq'] == '')
{
	$girl_qq = 'NULL';
}else{
	$girl_qq = checkqq($_POST['qq']);
}

if(is_uploaded_file($_FILES['upfile'.$i]['tmp_name'])){
	$file_type = $upfile['type'];
	$file_tmp_name = $upfile['tmp_name'];
	$time = time();
	
	switch($file_type){
		case 'image/pjpeg' : $ok=1;
		break;
		case 'image/jpeg' : $ok=1;
		break;
		case 'image/gif' : $ok=1;
		break;
		case 'image/png' : $ok=1;
		break;
		case 'image/x-png' : $ok=1;
		break;
		case 'image/x-ms-bmp' : $ok=1;
		break;
		case 'image/bmp' : $ok=1;
		break;
	}
	if($ok){
		$sql = "INSERT INTO `$top_man_tmp` (`name` ,`show` ,`grade` ,`branch` ,`dateline`,`mobile`,`qq`)";
		$sql.= " VALUES ('$girl_name', '$file_name', '$girl_grade', '$girl_branch', $time,$girl_mobile,$girl_qq)";
		//echo $sql;
		mysql_query($sql);
		move_uploaded_file($tmp_name,'show_tmp/'.$file_name);
	}else{
		$message = '异常错误，你可以尝试更换图片文件格式或者检查其他错误！';
		$message = rawurlencode($message);
		header("location:upload_error.php?error=$message");
		exit();
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN">
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  <title>上传成功</title>
	<style type="text/css">
		body { background-color: #DCDCDC; color: #666; text-align: center; font-family: arial, sans-serif; font-size:14px; }
		div.dialog {width: 500px;padding: 20px;margin: 50px auto;}
		h1 { font-size: 24px; letter-spacing:-1px; color: #f69; }
		a{ background:#fff; color:#f69; padding:8px 15px; margin:20px auto; display:block; width:190px; }
	</style>
</head>
<body>
  <div class="dialog">
    <h1>您上传的帅哥：<?=$girl_name;?></h1>    
    <h2>成功收录，请等待嘛嘻官方人工审核！</h2>
    <img src="<?php echo 'show_tmp/'.$file_name;?>" /><br />
    如果你不小心上传错了，请联系管理员:admin@fmash.com，你也可以再重新上传一份！
	<a href="./">&hearts; 点击返回首页 &rarr; </a>
  </div>
</body>
</html>